<template>
  <s-layout id="layout" :title="'商户号余额'" navbar="normal" leftIconColor="#333" :autoBack="false" :bgColor="state.bgColor"
    :tabbarshow='false' :titleStyle="{ color: '#333', fontSize: '32rpx' }">
    <view class="call_on" :style="{ paddingTop: (safeAreaInsets?.top + 44) + 'px' }">
      <scroll-view v-if="list.length" scroll-y class="comprehensive" @scrolltolower='listScrolltolower'
        show-scrollbar="true" :refresher-enabled="isOpenRefresh" :refresher-triggered="triggered"
        :refresher-threshold="100" refresher-background="white" @refresherpulling="onPulling"
        @refresherrefresh="onRefresh" @refresherrestore="onRestore" @refresherabort="onAbort" @scroll="onScroll">
        <view class="item_wrap">
          <view class="item" v-for="(item, index) in list" :key="index">
            <view class="item_left">
              <view class="img_title">
                <!-- <image :src="`${baseUrl}` + item.bank.logo" class="bankimg" mode="scaleToFill" /> -->
                <up-icon name="weixin-fill" color="#0ed068" size="28"></up-icon>
                <view class="title">
                  {{ item.name }}
                </view>
              </view>

              <view class="name_and_phone" v-if="item.data.available_amount">
                <text class="name">{{ item.data.available_amount}}</text>
              </view>                
              <view class="no_access" v-else>
                <text class="name">{{ item.data.message }}</text>
              </view> 
              <view class="addresss">

                <text>可用余额</text>
              </view>
            </view>
          </view>

        </view>
        <!-- 加载中 && 没有更多数据了 -->
        <!-- <view>
          <s-loadmore-gather :current_page="listPage" :last_page="listlast_page" ref="loadmoreRef"></s-loadmore-gather>
        </view> -->
      </scroll-view>
      <u-empty v-else mode="list" icon="http://cdn.uviewui.com/uview/empty/list.png" text="暂无内容"
        marginTop="50%"></u-empty>
    </view>

  </s-layout>
</template>

<script setup>
import { baseUrl } from '@/sheep/config';
import sheep from '@/sheep';
import { onLoad } from "@dcloudio/uni-app";
import { ref } from 'vue';
const { safeAreaInsets } = uni.getSystemInfoSync()
const state = ref({
  bgColor: '#fff'
})

onLoad(() => {
  list.value = [];
//   listpagenumber.value = 1;
  getList()
})
// 请求数据
const list = ref([])
const listPage = ref()
const listlast_page = ref();
const listpagenumber = ref(1);
const getList = async () => {
//   let params = {
//     page: listpagenumber.value,
//   };
  const res = await sheep.$api.account_statement.merchant_balanceList();
  list.value = res.data
//   list.value = [...list.value, ...res?.data.rows];
//   listPage.value = res.data.current_page
//   listlast_page.value = res.data.last_page
//   list.value.forEach(item => {
//     item.daytime = sheep.$helper.timeFrom(item.updatetime);

//   })
}
const loadmoreRef = ref()
//滚动触底
const listScrolltolower = () => {
  loadmoreRef.value.PopupScrolltolower()
  if (listPage.value < listlast_page.value) {
    listpagenumber.value += 1;
  } else {
    return;
  }
  getList();
};



//查看详情
const lookDetails = (item) => {
  item.logo = item.bank.logo
  sheep.$router.go('/subpackage/staff/workbench/account_statement/account_statement_detail', item);
}
// 页面下拉刷新
const freshing = ref(false)
const triggered = ref(false)
const isOpenRefresh = ref(true)  // 是否开启下拉
// 自定义下拉刷新控件被下拉
const onPulling = (e) => {
  if (e.detail.deltaY < 0) return  // 防止上滑页面也触发下拉
  triggered.value = true;
}
// 自定义下拉刷新被触发
const onRefresh = () => {
  if (freshing.value) return;
  freshing.value = true;
  setTimeout(() => {
    listpagenumber.value = 1;
    list.value = []
    triggered.value = false;
    freshing.value = false;
    getList();
  }, 500);
}
// 自定义下拉刷新被复位
const onRestore = () => {
  triggered.value = 'restore'; // 需要重置
}
// 自定义下拉刷新被中止
const onAbort = () => {
}
</script>

<style lang="scss" scoped>
.call_on {
  width: 100%;
  height: 100vh;
}

// 滚动
.comprehensive {
  width: calc(100% - 40rpx);
  background-color: rgba(0, 0, 0, 0);
  margin: 0 20rpx;
  height: 86vh;
}

//列表
.call_on {
  width: 100%;
  height: 89vh;

  .item_wrap {
    margin-top: 20rpx;

    .item {
      margin-bottom: 20rpx;
      border-radius: 16rpx;
      background-color: #FFFFFF;
      box-shadow: 0 4rpx 8rpx 0 rgba(0, 0, 0, 0.05);
      display: flex;
      justify-content: space-around;
      align-items: center;
      padding-bottom: 16rpx;

      .item_left {
        width: calc(100% - 30rpx);
        padding: 30rpx 0 0 30rpx;
        height: 168rpx;
        // flex-direction: column;
        font-family: PingFangSC;
        color: $uni-text-color;

        .title {
          font-weight: 500;
          font-size: 30rpx;
          padding-left: 8rpx;
        }

        .name_and_phone {
          .name {
            margin-right: 8rpx;
          }

          display: flex;
          align-items: center;
          color: $uni-text-color;
          font-weight: $uni-font-weight;
          font-size: 46rpx;
          margin-bottom: 10rpx;
        }

        .no_access {
            .name {
                margin-right: 8rpx;
            }
            display: flex;
            align-items: center;
            color: $uni-text-color;
            font-weight: $uni-font-weight;
            font-size: 40rpx;
            margin-bottom: 10rpx;
        }

        .addresss {
          display: flex;
          align-items: center;
          color: #999999;
          font-weight: 500;
          font-size: $uni-font-size-sm;
        }

      }

      .item_right {
        padding-right: 30rpx;
        display: flex;
        align-items: flex-end;
        flex-direction: column;

        .update {
          color: #666666;
          font-weight: 500;
          font-size: $uni-font-size-sm;
          margin-bottom: 60rpx;

        }

        .name {
          width: 82px;
          height: 52rpx;
          border-radius: 26rpx;
          color: $uni-color-primary;
          font-weight: 500;
          font-size: $uni-font-size-sm;
          line-height: 52rpx;
          text-align: center;
          background: linear-gradient(90deg, rgba(0, 56, 247, 0.1) 0%, rgba(77, 139, 255, 0.1) 100%);
        }
      }
    }
  }
}

//银行卡图片
.bankimg {
  width: 50rpx;
  height: 50rpx;
  border-radius: 50%;
}

.img_title {
  display: flex;
  height: 60rpx;
  align-items: center;
  margin-bottom: 10rpx;
}
</style>